# -*- coding: utf-8 -*-
# @Time    : 2024/11/29  14:40
# @Author  : Nabby
# @FileName: order_api.py
# @Desc    :

from app import app, request
from application.jasco_order_manage import JascoOrderService
from application import upload_manage
from infrastructure.utils.http import responser
from infrastructure.utils.decorator.oauth2_tool import oauth2_check

@app.route("/api/get_order_list", endpoint="get_order_list", methods=["POST"])
@oauth2_check
def get_order_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "page",
            "pageSize",
            "userId"
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_jasco_order_list(
            user_id=rjson.get("userId"),
            order_code=rjson.get("orderCode", None),
            logistics_code=rjson.get("logisticsCode", None),
            consignee=rjson.get("consignee", None),
            destination=rjson.get("destination", None),
            postcode=rjson.get("postcode", None),
            # keyword=rjson.get("keyword", None),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )

@app.route("/api/get_order_detail", endpoint="get_order_detail", methods=["POST"])
@oauth2_check
def get_order_detail():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_jasco_order_by_id(
            id=rjson.get("orderId"),
        )
    else:
        return rjson

@app.route("/api/add_order", endpoint="add_order", methods=["POST"])
@oauth2_check
def add_order():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "userId",
            "orderCode",
            "logisticsCode",
            "consignee",
            "destination",
            "postcode",
            # "keyword",
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_order(
            user_id=rjson.get("userId"),
            order_code=rjson.get("orderCode"),
            order_status=rjson.get("status", None),
            order_type=rjson.get("type", None),
            logistics_code=rjson.get("logisticsCode", None),
            logistics_channel=rjson.get("logisticsChannel", None),
            receiving_time=rjson.get("receivingTime", None),
            consignee=rjson.get("consignee", None),
            consignee_company=rjson.get("consigneeCompany", None),
            consignee_phone=rjson.get("consigneePhone", None),
            consignee_email=rjson.get("consigneeEmail", None),
            postcode=rjson.get("postcode", None),
            destination=rjson.get("destination", None),
            has_insure=rjson.get("hasInsure", None),
            # keyword=rjson.get("keyword", None),
            clearance_type=rjson.get("clearanceType", None),
            trade_clause=rjson.get("tradeClause", None),
            tfn_vat=rjson.get("tfnVat", None),
            tfn_eori=rjson.get("tfnEori", None),
            tfn_ein=rjson.get("tfnEin", None),
            tfn_other=rjson.get("tfnOther", None),
            packages_num=rjson.get("packagesNum", None),
            address1=rjson.get("address1", None),
            address2=rjson.get("address2", None),
            address3=rjson.get("address3", None),
            packages_weight=rjson.get("packagesWeight", None),
            packages_volume=rjson.get("packagesVolume", None),
            billing_weight_squaremeter=rjson.get("billingWeightSquaremeter", None),
            volume_divisor=rjson.get("volumeDivisor", None)
        )
    else:
        return rjson

@app.route("/api/edit_order", endpoint="edit_order", methods=["POST"])
@oauth2_check
def edit_order():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "orderCode",
            "orderStatus",
            "orderType",
            "logisticsCode",
            "logisticsChannel",
            "receivingTime",
            "consignee",
            "consigneeCompany",
            "consigneePhone",
            "consigneeEmail",
            "postcode",
            "destination",
            "hasInsure",
            # "keyword",
            "clearanceType",
            "tradeClause",
            "tfnVat",
            "tfnEori",
            "tfnEin",
            "tfnOther",
            "packagesNum",
            "address1",
            "address2",
            "address3",
            "packagesWeight",
            "packagesVolume",
            "billingWeightSquaremeter",
            "volumeDivisor"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_order(
            order_id=rjson.get("orderId"),
            order_code=rjson.get("orderCode"),
            order_status=rjson.get("orderStatus", None),
            order_type=rjson.get("orderType", None),
            logistics_code=rjson.get("logisticsCode", None),
            logistics_channel=rjson.get("logisticsChannel", None),
            receiving_time=rjson.get("receivingTime", None),
            consignee=rjson.get("consignee", None),
            consignee_company=rjson.get("consigneeCompany", None),
            consignee_phone=rjson.get("consigneePhone", None),
            consignee_email=rjson.get("consigneeEmail", None),
            postcode=rjson.get("postcode", None),
            destination=rjson.get("destination", None),
            has_insure=rjson.get("hasInsure", None),
            # keyword=rjson.get("keyword", None),
            clearance_type=rjson.get("clearanceType", None),
            trade_clause=rjson.get("tradeClause", None),
            tfn_vat=rjson.get("tfnVat", None),
            tfn_eori=rjson.get("tfnEori", None),
            tfn_ein=rjson.get("tfnEin", None),
            tfn_other=rjson.get("tfnOther", None),
            packages_num=rjson.get("packagesNum", None),
            address1=rjson.get("address1", None),
            address2=rjson.get("address2", None),
            address3=rjson.get("address3", None),
            packages_weight=rjson.get("packagesWeight", None),
            packages_volume=rjson.get("packagesVolume", None),
            billing_weight_squaremeter=rjson.get("billingWeightSquaremeter", None),
            volume_divisor=rjson.get("volumeDivisor", None)
        )
    else:
        return rjson

@app.route("/api/delete_order", endpoint="delete_order", methods=["POST"])
@oauth2_check
def delete_order():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.delete_order(
            order_id=rjson.get("orderId"),
        )
    else:
        return rjson




@app.route("/api/get_cargo_detail_overview", endpoint="get_cargo_detail_overview", methods=["POST"])
@oauth2_check
def get_cargo_detail_overview():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_cargo_detail_overview(
            order_id=rjson.get("orderId"),
        )
    else:
        return rjson

@app.route("/api/edit_cargo_detail_overview", endpoint="edit_cargo_detail_overview", methods=["POST"])
@oauth2_check
def edit_cargo_detail_overview():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "packagesNum",
            "packagesWeight",
            "packagesVolume",
            "billingWeightSquaremeter",
            "volumeDivisor"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_cargo_detail_overview(
            order_id=rjson.get("orderId"),
            packages_num=rjson.get("packagesNum"),
            packages_weight=rjson.get("packagesWeight"),
            packages_volume=rjson.get("packagesVolume"),
            billing_weight_squaremeter=rjson.get("billingWeightSquaremeter"),
            volume_divisor=rjson.get("volumeDivisor")
        )
    else:
        return rjson

@app.route("/api/get_order_forecast_information_list", endpoint="get_order_forecast_information_list", methods=["POST"])
@oauth2_check
def get_order_forecast_information_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "page",
            "pageSize",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_order_forecast_information_list(
            order_id=rjson.get("orderId"),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )

@app.route("/api/add_order_forecast_information", endpoint="add_order_forecast_information", methods=["POST"])
@oauth2_check
def add_order_forecast_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "cargoCode",
            "length",
            "width",
            "height",
            "grossWeight",
            "volume"
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_order_forecast_information(
            order_id=rjson.get("orderId"),
            cargo_code=rjson.get("cargoCode"),
            length=rjson.get("length"),
            width=rjson.get("width"),
            height=rjson.get("height"),
            gross_weight=rjson.get("grossWeight"),
            volume=rjson.get("volume")
        )
    else:
        return rjson

@app.route("/api/edit_order_forecast_information", endpoint="edit_order_forecast_information", methods=["POST"])
@oauth2_check
def edit_order_forecast_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "forecastInformationId",
            "orderId",
            "cargoCode",
            "length",
            "width",
            "height",
            "grossWeight",
            "volume"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_order_forecast_information(
            forecast_information_id=rjson.get("forecastInformationId"),
            order_id=rjson.get("orderId"),
            cargo_code=rjson.get("cargoCode"),
            length=rjson.get("length"),
            width=rjson.get("width"),
            height=rjson.get("height"),
            gross_weight=rjson.get("grossWeight"),
            volume=rjson.get("volume")
        )
    else:
        return rjson

@app.route("/api/delete_order_forecast_information", endpoint="delete_order_forecast_information", methods=["POST"])
@oauth2_check
def delete_order_forecast_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "forecastInformationId",
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.delete_order_forecast_information(
            id=rjson.get("forecastInformationId"),
            order_id=rjson.get("orderId"),
        )
    else:
        return rjson

@app.route("/api/get_order_received_information_list", endpoint="get_order_received_information_list", methods=["POST"])
@oauth2_check
def get_order_received_information_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "page",
            "pageSize",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_order_received_information_list(
            order_id=rjson.get("orderId"),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )

@app.route("/api/add_order_received_information", endpoint="add_order_received_information", methods=["POST"])
@oauth2_check
def add_order_received_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "cargoCode",
            "length",
            "width",
            "height",
            "actualWeight",
            "volumetricWeight",
            "billingWeight",
            "billingSquaremeter",
            "subBillCode",
            "transportationStatus",
            "volume"
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_order_received_information(
            order_id=rjson.get("orderId"),
            cargo_code=rjson.get("cargoCode"),
            length=rjson.get("length"),
            width=rjson.get("width"),
            height=rjson.get("height"),
            actual_weight=rjson.get("actualWeight"),
            volume=rjson.get("volume"),
            volumetric_weight=rjson.get("volumetricWeight"),
            billing_weight=rjson.get("billingWeight"),
            billing_squaremeter=rjson.get("billingSquaremeter"),
            sub_bill_code=rjson.get("subBillCode"),
            transportation_status=rjson.get("transportationStatus")
        )
    else:
        return rjson

@app.route("/api/edit_order_received_information", endpoint="edit_order_received_information", methods=["POST"])
@oauth2_check
def edit_order_received_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "receivedInformationId",
            "orderId",
            "cargoCode",
            "length",
            "width",
            "height",
            "actualWeight",
            "volumetricWeight",
            "billingWeight",
            "billingSquaremeter",
            "subBillCode",
            "transportationStatus",
            "volume"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_order_received_information(
            received_information_id=rjson.get("receivedInformationId"),
            order_id=rjson.get("orderId"),
            cargo_code=rjson.get("cargoCode"),
            length=rjson.get("length"),
            width=rjson.get("width"),
            height=rjson.get("height"),
            actual_weight=rjson.get("actualWeight"),
            volume=rjson.get("volume"),
            volumetric_weight=rjson.get("volumetricWeight"),
            billing_weight=rjson.get("billingWeight"),
            billing_squaremeter=rjson.get("billingSquaremeter"),
            sub_bill_code=rjson.get("subBillCode"),
            transportation_status=rjson.get("transportationStatus")
        )
    else:
        return rjson

@app.route("/api/delete_order_received_information", endpoint="delete_order_received_information", methods=["POST"])
@oauth2_check
def delete_order_received_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "receivedInformationId",
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.delete_order_received_information(
            id=rjson.get("receivedInformationId"),
            order_id=rjson.get("orderId"),
        )
    else:
        return rjson

@app.route("/api/get_order_declaration_information_list", endpoint="get_order_declaration_information_list", methods=["POST"])
@oauth2_check
def get_order_declaration_information_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "page",
            "pageSize",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_order_declaration_information_list(
            order_id=rjson.get("orderId"),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )

@app.route("/api/add_order_declaration_information", endpoint="add_order_declaration_information", methods=["POST"])
@oauth2_check
def add_order_declaration_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "totalProducts",
            "declaredValue",
            "nameQuantity"
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_order_declaration_information(
            order_id=rjson.get("orderId"),
            total_products=rjson.get("totalProducts"),
            declared_value=rjson.get("declaredValue"),
            name_quantity=rjson.get("nameQuantity"),
            english_name=rjson.get("englishName"),
            chinese_name=rjson.get("chineseName"),
            customs_code=rjson.get("customsCode"),
            products_num=rjson.get("productsNum"),
            chinese_material=rjson.get("chineseMaterial"),
            english_material=rjson.get("englishMaterial"),
            chinese_use=rjson.get("chineseUse"),
            english_use=rjson.get("englishUse"),
            brand=rjson.get("brand"),
            model=rjson.get("model"),
            online_link=rjson.get("onlineLink"),
            product_picture=rjson.get("productPicture"),
            unit=rjson.get("unit"),
            price=rjson.get("price"),
            currency=rjson.get("currency"),
            total_price=rjson.get("totalPrice"),
            net_weight=rjson.get("netWeight"),
            source_area=rjson.get("sourceArea"),
            final_destination=rjson.get("finalDestination")
        )
    else:
        return rjson

@app.route("/api/edit_order_declaration_information", endpoint="edit_order_declaration_information", methods=["POST"])
@oauth2_check
def edit_order_declaration_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "declarationInformationId",
            "orderId",
            "totalProducts",
            "declaredValue",
            "nameQuantity",
            "englishName",
            "chineseName",
            "customsCode",
            "productsNum",
            "chineseMaterial",
            "englishMaterial",
            "chineseUse",
            "englishUse",
            "brand",
            "model",
            "onlineLink",
            "productPicture",
            "unit",
            "price",
            "currency",
            "totalPrice",
            "netWeight",
            "sourceArea",
            "finalDestination"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_order_declaration_information(
            declaration_information_id=rjson.get("declarationInformationId"),
            order_id=rjson.get("orderId"),
            total_products=rjson.get("totalProducts"),
            declared_value=rjson.get("declaredValue"),
            name_quantity=rjson.get("nameQuantity"),
            english_name=rjson.get("englishName"),
            chinese_name=rjson.get("chineseName"),
            customs_code=rjson.get("customsCode"),
            products_num=rjson.get("productsNum"),
            chinese_material=rjson.get("chineseMaterial"),
            english_material=rjson.get("englishMaterial"),
            chinese_use=rjson.get("chineseUse"),
            english_use=rjson.get("englishUse"),
            brand=rjson.get("brand"),
            model=rjson.get("model"),
            online_link=rjson.get("onlineLink"),
            product_picture=rjson.get("productPicture"),
            unit=rjson.get("unit"),
            price=rjson.get("price"),
            currency=rjson.get("currency"),
            total_price=rjson.get("totalPrice"),
            net_weight=rjson.get("netWeight"),
            source_area=rjson.get("sourceArea"),
            final_destination=rjson.get("finalDestination")
        )
    else:
        return rjson

@app.route("/api/delete_order_declaration_information", endpoint="delete_order_declaration_information", methods=["POST"])
@oauth2_check
def delete_order_declaration_information():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "declarationInformationId",
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.delete_order_declaration_information(
            id=rjson.get("declarationInformationId"),
            order_id=rjson.get("orderId"),
        )
    else:
        return rjson

@app.route("/api/get_order_loading_order_list", endpoint="get_order_loading_order_list", methods=["POST"])
@oauth2_check
def get_order_loading_order_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "declarationInformationId",
            "page",
            "pageSize",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_order_loading_order_list(
            declaration_information_id=rjson.get("declarationInformationId"),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )

@app.route("/api/add_order_loading_order", endpoint="add_order_loading_order", methods=["POST"])
@oauth2_check
def add_order_loading_order():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "declarationInformationId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_order_loading_order(
            declaration_information_id=rjson.get("declarationInformationId"),
            container_number=rjson.get("containerNumber"),
            english_name=rjson.get("englishName"),
            chinese_name=rjson.get("chineseName"),
            customs_code=rjson.get("customsCode"),
            products_num=rjson.get("productsNum"),
            chinese_material=rjson.get("chineseMaterial"),
            english_material=rjson.get("englishMaterial"),
            chinese_use=rjson.get("chineseUse"),
            english_use=rjson.get("englishUse"),
            brand=rjson.get("brand"),
            model=rjson.get("model"),
            unit=rjson.get("unit"),
            price=rjson.get("price"),
            currency=rjson.get("currency"),
            total_price=rjson.get("totalPrice"),
            net_weight=rjson.get("netWeight"),
            source_area=rjson.get("sourceArea"),
            final_destination=rjson.get("finalDestination")
        )
    else:
        return rjson

@app.route("/api/edit_order_loading_order", endpoint="edit_order_loading_order", methods=["POST"])
@oauth2_check
def edit_order_loading_order():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "loadingOrderId",
            "declarationInformationId",
            "containerNumber",
            "englishName",
            "chineseName",
            "customsCode",
            "productsNum",
            "chineseMaterial",
            "englishMaterial",
            "chineseUse",
            "englishUse",
            "brand",
            "model",
            "unit",
            "price",
            "currency",
            "totalPrice",
            "netWeight",
            "sourceArea",
            "finalDestination"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_order_loading_order(
            loading_order_id=rjson.get("loadingOrderId"),
            declaration_information_id=rjson.get("declarationInformationId"),
            container_number=rjson.get("containerNumber"),
            english_name=rjson.get("englishName"),
            chinese_name=rjson.get("chineseName"),
            customs_code=rjson.get("customsCode"),
            products_num=rjson.get("productsNum"),
            chinese_material=rjson.get("chineseMaterial"),
            english_material=rjson.get("englishMaterial"),
            chinese_use=rjson.get("chineseUse"),
            english_use=rjson.get("englishUse"),
            brand=rjson.get("brand"),
            model=rjson.get("model"),
            unit=rjson.get("unit"),
            price=rjson.get("price"),
            currency=rjson.get("currency"),
            total_price=rjson.get("totalPrice"),
            net_weight=rjson.get("netWeight"),
            source_area=rjson.get("sourceArea"),
            final_destination=rjson.get("finalDestination")
        )
    else:
        return rjson

@app.route("/api/delete_order_loading_order", endpoint="delete_order_loading_order", methods=["POST"])
@oauth2_check
def delete_order_loading_order():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "loadingOrderId",
            "declarationInformationId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.delete_order_loading_order(
            loading_order_id=rjson.get("loadingOrderId"),
            declaration_information_id=rjson.get("declarationInformationId"),
        )
    else:
        return rjson

@app.route("/api/get_cost_details_list", endpoint="get_cost_details_list", methods=["POST"])
@oauth2_check
def get_cost_details_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "page",
            "pageSize",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_cost_details_list(
            order_id=rjson.get("orderId"),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )
    else:
        return rjson

@app.route("/api/add_cost_details", endpoint="add_cost_details", methods=["POST"])
@oauth2_check
def add_cost_details():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_cost_details(
            order_id=rjson.get("orderId"),
            item=rjson.get("item"),
            cost=rjson.get("cost"),
            currency=rjson.get("currency"),
            ssr=rjson.get("ssr"),
            settlement_status=rjson.get("settlementStatus")
        )
    else:
        return rjson

@app.route("/api/edit_cost_details", endpoint="edit_cost_details", methods=["POST"])
@oauth2_check
def edit_cost_details():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "costDetailsId",
            "orderId",
            "item",
            "cost",
            "currency",
            "ssr",
            "settlementStatus"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_cost_details(
            cost_detail_id=rjson.get("costDetailsId"),
            order_id=rjson.get("orderId"),
            item=rjson.get("item"),
            cost=rjson.get("cost"),
            currency=rjson.get("currency"),
            ssr=rjson.get("ssr"),
            settlement_status=rjson.get("settlementStatus")
        )
    else:
        return rjson

@app.route("/api/delete_cost_details", endpoint="delete_cost_details", methods=["POST"])
@oauth2_check
def delete_cost_details():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "costDetailsId",
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.delete_cost_details(
            cost_details_id=rjson.get("costDetailsId"),
            order_id=rjson.get("orderId"),
        )
    else:
        return rjson

@app.route("/api/get_logistics_trajectory_list", endpoint="get_logistics_trajectory_list", methods=["POST"])
@oauth2_check
def get_logistics_trajectory_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "page",
            "pageSize",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_logistics_trajectory_list(
            order_id=rjson.get("orderId"),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )
    else:
        return rjson

@app.route("/api/add_logistics_trajectory", endpoint="add_logistics_trajectory", methods=["POST"])
@oauth2_check
def add_logistics_trajectory():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_logistics_trajectory(
            order_id=rjson.get("orderId"),
            status=rjson.get("status"),
            date=rjson.get("date"),
            content=rjson.get("content"),
            location=rjson.get("location")
        )
    else:
        return rjson

@app.route("/api/edit_logistics_trajectory", endpoint="edit_logistics_trajectory", methods=["POST"])
@oauth2_check
def edit_logistics_trajectory():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "logisticsTrajectoryId",
            "orderId",
            "status",
            "date",
            "content",
            "location"
        ],
    )
    if res_status == "success":
        return JascoOrderService.edit_logistics_trajectory(
            logistics_trajectory_id=rjson.get("logisticsTrajectoryId"),
            order_id=rjson.get("orderId"),
            status=rjson.get("status"),
            date=rjson.get("date"),
            content=rjson.get("content"),
            location=rjson.get("location")
        )
    else:
        return rjson

@app.route("/api/delete_logistics_trajectory", endpoint="delete_logistics_trajectory", methods=["POST"])
@oauth2_check
def delete_logistics_trajectory():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "logisticsTrajectoryId",
            "orderId",
        ],
    )
    if res_status == "success":
        return JascoOrderService.delete_logistics_trajectory(
            logistics_trajectory_id=rjson.get("logisticsTrajectoryId"),
            order_id=rjson.get("orderId"),
        )
    else:
        return rjson

@app.route("/api/get_file_list", endpoint="get_file_list", methods=["POST"])
@oauth2_check
def get_file_list():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "page",
            "pageSize",
        ],
    )
    if res_status == "success":
        return JascoOrderService.get_file_list(
            order_id=rjson.get("orderId"),
            page=rjson.get("page", 1),
            page_size=rjson.get("pageSize", 999)
        )
    else:
        return rjson

@app.route("/api/add_file", endpoint="add_file", methods=["POST"])
@oauth2_check
def add_file():
    res_status, rjson = responser.post_param_check(
        request,
        [
            "orderId",
            "fileName",
            "filePath",
            "type",
        ],
    )
    if res_status == "success":
        return JascoOrderService.add_file(
            order_id=rjson.get("orderId"),
            type=rjson.get("type"),
            file_name=rjson.get("fileName"),
            source=rjson.get("source"),
            remark=rjson.get("remark"),
            file_path=rjson.get("filePath"),
            etd=rjson.get("etd"),
            pol=rjson.get("pol"),
            company_name=rjson.get("companyName"),
            linkman=rjson.get("linkman"),
            phone=rjson.get("phone"),
            email=rjson.get("email"),
            invoice_number=rjson.get("invoiceNumber"),
            goods_name=rjson.get("goodsName"),
            loading_time=rjson.get("loadingTime"),
            total_packages=rjson.get("totalPackages"),
            total_weight=rjson.get("totalWeight"),
            total_volume=rjson.get("totalVolume"),
            atd=rjson.get("atd"),
            actual_pol=rjson.get("actualPol"),
            eta=rjson.get("eta"),
            pod=rjson.get("pod"),
            vel=rjson.get("vel"),
            mbl=rjson.get("mbl"),
            hbl=rjson.get("hbl"),
            deliver_to=rjson.get("deliverTo"),
            terms=rjson.get("terms")
        )
    else:
        return rjson

@app.route("/api/upload_file", endpoint="upload_file", methods=["POST"])
@oauth2_check
def upload_file():
    return upload_manage.upload_file(request)


# @app.route("/api/delete_file", endpoint="delete_file", methods=["POST"])
# @oauth2_check
# def delete_file():
#     res_status, rjson = responser.post_param_check(
#         request,
#         [
#             "fileId",
#             "orderId",
#         ],
#     )
#     if res_status == "success":
#         return JascoOrderService.delete_file(
#             file_id=rjson.get("fileId"),
#             order_id=rjson.get("orderId"),
#         )
#     else:
#         return rjson